/*
 ============================================================================
 Name        : Set_CGI.c
 Author      : liuzhanchun
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#if 1
#define SERVER_NAME cgiServerName
#endif
#if 0
#define SERVER_NAME "www.boutell.com"
#endif

/* You may need to change this, particularly under Windows;
	it is a reasonable guess as to an acceptable place to
	store a saved environment in order to test that feature.
	If that feature is not important to you, you needn't
	concern yourself with this. */

#ifdef WIN32
#define SAVED_ENVIRONMENT "c:\\cgicsave.env"
#else
#define SAVED_ENVIRONMENT "/tmp/cgicsave.env"
#endif /* WIN32 */

#include <stdio.h>
#include "cgic.h"
#include <string.h>
#include <stdlib.h>
#include "config_ini.h"
//系统管理
int cgiMain() {
    /*从html获取数据，设置cookie*/
    char user_name[32] = {0};
	cgiFormString("user_name", user_name, 32);
	fprintf(cgiOut,"Set-Cookie: %s=%s;  path=/\r\n","user_name",user_name);

	char user_password[32] = {0};
	cgiFormString("user_password", user_password, 32);
	fprintf(cgiOut,"Set-Cookie: %s=%s;  path=/\r\n","user_password",user_password);
	
	char language[32] = {0};
	cgiFormString("language", language, 32);
    fprintf(cgiOut,"Set-Cookie: %s=%s;  path=/\r\n","language",language);

	//date time
	
	char equipment_mode[32] = {0};
	cgiFormString("equipment_mode", equipment_mode, 32);
    fprintf(cgiOut,"Set-Cookie: %s=%s;  path=/\r\n","equipment_mode",equipment_mode);

	char equipment_serial_number[32] = {0};
	cgiFormString("equipment_serial_number", equipment_serial_number, 32);
    fprintf(cgiOut,"Set-Cookie: %s=%s;  path=/\r\n","equipment_serial_number",equipment_serial_number);

	char fpga_version[32] = {0};
	cgiFormString("fpga_version", fpga_version, 32);
    fprintf(cgiOut,"Set-Cookie: %s=%s;  path=/\r\n","fpga_version",fpga_version);

	char arm_version[32] = {0};
	cgiFormString("arm_version", arm_version, 32);
    fprintf(cgiOut,"Set-Cookie: %s=%s;  path=/\r\n","arm_version",arm_version);

	char web_version[32] = {0};
	cgiFormString("web_version", web_version, 32);
    fprintf(cgiOut,"Set-Cookie: %s=%s;  path=/\r\n","web_version",web_version);

	/* Send the content type, letting the browser know this is HTML */
	cgiHeaderContentType("text/html; charset=UTF-8");

	/* Top of the page */
	fprintf(cgiOut, "<HTML><HEAD>\n");
	fprintf(cgiOut, "<TITLE>web 管理</TITLE></HEAD>\n");
	fprintf(cgiOut, "<BODY><H1></H1>\n");

	//存储数据
	configFileStrSet("/boa/my.ini","user_name",user_name);
	configFileStrSet("/boa/my.ini","user_password",user_password);
	configFileStrSet("/boa/my.ini","language_setting",language);
	fprintf(cgiOut, "222 %s\n", language);
	//date time
	configFileStrSet("/boa/my.ini","equipment_mode",equipment_mode);
	configFileStrSet("/boa/my.ini","equipment_serial_number",equipment_serial_number);
	configFileStrSet("/boa/my.ini","fpga_version",fpga_version);
	configFileStrSet("/boa/my.ini","arm_version",arm_version);
	configFileStrSet("/boa/my.ini","web_version",web_version);

	//刷新页面
	fprintf(cgiOut, "<meta http-equiv=Refresh content=0;URL=../manager.html\n");
	fprintf(cgiOut, "</BODY></HTML>\n");

	return 0;
}

